package com.xdb.sqlparser.dialect.mysql.ast.statement;

import com.xdb.sqlparser.ast.statement.SQLUnionQuery;
import com.xdb.sqlparser.dialect.mysql.ast.MySqlObject;
import com.xdb.sqlparser.dialect.mysql.ast.statement.MySqlSelectQueryBlock.Limit;
import com.xdb.sqlparser.dialect.mysql.visitor.MySqlASTVisitor;
import com.xdb.sqlparser.visitor.SQLAstVisitor;

public class MySqlUnionQuery extends SQLUnionQuery implements MySqlObject {

	private Limit limit;

	public Limit getLimit() {
		return limit;
	}

	public void setLimit(Limit limit) {
		if (limit != null) {
			limit.setParent(this);
		}
		this.limit = limit;
	}

	@Override
	protected void accept0(SQLAstVisitor visitor) {
		if (visitor instanceof MySqlASTVisitor) {
			accept0((MySqlASTVisitor) visitor);
		} else {
			throw new IllegalArgumentException("not support visitor type : " + visitor.getClass().getName());
		}
	}

	@Override
	public void accept0(MySqlASTVisitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, getLeft());
			acceptChild(visitor, getRight());
			acceptChild(visitor, getOrderBy());
			acceptChild(visitor, getLimit());
		}
		visitor.endVisit(this);
	}
}
